package com.club.football.controller;

import com.club.football.dto.EventsSaveDto;
import com.club.football.dto.PageDto;
import com.club.football.entity.Coach;
import com.club.football.entity.Events;
import com.club.football.req.EventsPageReq;
import com.club.football.service.EventsService;
import com.club.football.utils.R;
import com.club.football.vo.EventsPageVo;
import com.club.football.vo.EventsVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.club.football.common.CommonConstants.DEL_OK_MSG;

/**
 * 赛事Controller
 *
 * @author 1
 * @date 2023/12/28
 */
@RestController
@RequestMapping("/events")
public class EventsController {
    @Resource
    private EventsService eventsService;


    /**
     * 页面
     *
     * @param pageDto 页数到页
     * @return {@link R}
     */
    @GetMapping("/page")
    public R<PageDto<EventsPageVo>> page(PageDto<Events> pageDto, EventsPageReq eventsPageReq) {
        return eventsService.eventsPage(pageDto, eventsPageReq);
    }

    /**
     * 球队保存
     *
     * @return {@link R}<{@link String}>
     */
    @PostMapping("/save")
    public R<String> save(@RequestBody @Valid EventsSaveDto saveDto) {
        return eventsService.eventsSave(saveDto);
    }

    /**
     * 删除
     *
     * @param id ID
     * @return {@link R}<{@link String}>
     */
    @DeleteMapping("/remove/{id}")
    public R<String> remove(@PathVariable Long id) {
        eventsService.removeById(id);
        return R.ok(DEL_OK_MSG);
    }

    /**
     * 信息
     *
     * @param id ID
     * @return {@link R}<{@link Coach}>
     */
    @GetMapping("/info/{id}")
    public R<EventsVo> info(@PathVariable Long id) {
        return eventsService.eventsInfo(id);
    }
}
